package cn.tedu.ivos.application.controller;

import cn.tedu.ivos.application.pojo.dto.ApplicationQueryParam;
import cn.tedu.ivos.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivos.application.pojo.entity.Application;
import cn.tedu.ivos.application.pojo.vo.ApplicationVO;
import cn.tedu.ivos.application.service.ApplicationService;
import cn.tedu.ivos.base.response.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "申请模块")
@Slf4j
@RestController
@RequestMapping("/v1/application/")
public class ApplicationController {

    @Autowired
    ApplicationService applicationService;

    @PostMapping("save")
    @Operation(summary = "申请表单")
    @ApiOperationSupport(order = 10)
    public JsonResult sace(@Validated ApplicationSaveParam param){
    log.debug("申请表单："+param);
    applicationService.save(param);
    return JsonResult.ok();
    }

    @GetMapping("select")
    @Operation(summary = "查询申请列表")
    @ApiOperationSupport(order = 20)
    public JsonResult selectList(ApplicationQueryParam param){
        log.debug("查询申请列表"+param);
        List<ApplicationVO> list=applicationService.selectApplication(param);
        return JsonResult.ok(list);
    }

    @PostMapping("cancel/{id}")
    @Operation(summary = "取消申请")
    @ApiOperationSupport(order = 30)
    public JsonResult cancel(@PathVariable Long id){
        log.debug("取消申请"+id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }

    @PostMapping("distribute/{applicationId}/{vehicleId}")
    @Operation(summary = "分配车辆")
    @ApiOperationSupport(order = 40)
    public JsonResult distribute(@PathVariable Long applicationId,@PathVariable Long vehicleId){
        log.debug("分配车辆信息:"+applicationId+"--"+vehicleId);
        applicationService.distribute(applicationId,vehicleId);
        return JsonResult.ok();
    }

    @PostMapping("/back/{id}/{vehicleId}")
    @Operation(summary = "还车")
    @ApiOperationSupport
    public JsonResult returnCar(@PathVariable Long id,@PathVariable Long vehicleId){
        log.debug("还车信息："+id+"--"+vehicleId);
        applicationService.returnCar(id,vehicleId);
        return JsonResult.ok();
    }

}
